package com.easymin.daijia.server;

import com.ybkj.daijia.server.mapper.Log4jLogMapper;
import com.ybkj.daijia.server.model.Log4JLog;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zhyu
 * @date 2019-06-26 17:18:55
 */
public class Log4JCase extends TestBase {

    Logger log = LoggerFactory.getLogger("db");

    public Log4JCase() throws IOException {
    }

    @Test
    public void test1() {
        Log4jLogMapper mapper = session.getMapper(Log4jLogMapper.class);
        Map<String, Object> map = new HashMap<>();
        map.put("start", "2019-06-26 16:00:00");
        map.put("end", "2019-06-26 18:00:00");
        System.out.println("size :" + mapper.countByMap(map));
        map.put("offset", 0);
        map.put("size", 2);

        System.out.println(mapper.selectByMap(map));
    }

    @Test
    public void test2() {
        Log4jLogMapper mapper = session.getMapper(Log4jLogMapper.class);
        Map<String, Object> map = new HashMap<>();
        map.put("offset", 0);
        map.put("size", 20);
        map.put("level", "INFO");
        map.put("location", "server");
//        map.put("thread","main");
        System.out.println(mapper.selectByMap(map));
        System.out.println(mapper.countByMap(map));
    }

    @Test
    public void test3() {
        Log4jLogMapper mapper = session.getMapper(Log4jLogMapper.class);
        for (int i = 0; i < 100; i++) {
            Log4JLog log = new Log4JLog();
            log.setInfo(
                "test xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            log.setHappen(new Date());
            log.setLevel("info");
            log.setLocation("test location" + i);
            log.setThread("test thread");
            mapper.insert(log);
            System.out.println(log);
        }
        session.commit();
    }

    @Test
    public void test4() {
        for (int i = 0; i < 30; i++) {
            if (i > 14) {
                log.info("test hello" + i);
            } else {
                log.error("test hello" + i);
            }
        }
    }
}
